package com.tuanzi.loan.web.lazy.statistics;

import com.tuanzi.loan.business.service.statistics.LoanAdvertiseTransFormationService;
import com.tuanzi.loan.core.lazy.BaseLazyDataModel;
import com.tuanzi.loan.core.util.SpringContextHolder;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.advertise.AdvertiseTransStatRequest;
import com.tuanzi.loan.vo.response.advertise.AdvertiseTransStatResponse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;

import java.util.Collections;

/**
 * 撞库统计 DataModel
 *
 * created by chuIllusions_tan 20180730
 */
public class AdvertiseTransStatDataModel extends BaseLazyDataModel<AdvertiseTransStatRequest, AdvertiseTransStatResponse>{

    private Boolean isFirst = true;

    private LoanAdvertiseTransFormationService advertiseTransStatService = SpringContextHolder.getBean(LoanAdvertiseTransFormationService.class);

    public AdvertiseTransStatDataModel(AdvertiseTransStatRequest advertiseTransStatRequest) {
        super(advertiseTransStatRequest);
    }

    @Override
    protected Page<AdvertiseTransStatResponse> doLoad(PageSearcher<AdvertiseTransStatRequest> pageSearcher) {
        if (isFirst){
            isFirst = false;
            return new PageImpl<>(Collections.emptyList());
        }

        return advertiseTransStatService.list(pageSearcher);
    }
}
